The CFileSys class wraps the Microsoft File System Object and provides methods to work with files and folders, giving your application the ability to create, copy, alter, move, and delete files and folders, or to determine if and where particular files or folders exist. It also enables you to get information about files and folders, such as their names and the date they were created or last modified.
Include file: CFileSys.inc
| Name | Description |
|---|---|
| BuildPath | Appends a name to an existing path. |
| CopyFile | Copies one or more files from one location to another. |
| CopyFolder | Recursively copies a folder from one location to another. |
| CreateFolder | Creates a folder. |
| DeleteFile | Deletes a specified file. |
| DeleteFolder | Deletes a specified folder and its contents. |
| DriveExists | Checks if the specified drive exists. |
| DriveLetters | Returns a semicolon separated list with the driver letters. |
| FileExists | Checks for the existence of the specified file. |
| FolderExists | Checks for the existence of the specified folder. |
| GetAbsolutePathName | Returns complete and unambiguous path from a provided path specification. |
| GetBaseName | Returns a string containing the base name of the last component, less any file extension, in a path. |
| GetDriveAvailableSpace | Returns the amount of space available to a user on the specified drive or network share. |
| GetDriveFileSystem | Returns the type of file system in use for the specified drive or network share. |
| GetDriveFreeSpace | Returns the amount of free space available to a user on the specified drive or network share. |
| GetDriveName | Returns a string containing the name of the drive for a specified path. |
| GetDriveShareName | Returns the network share name for a specified drive. |
| GetDriveTotalSize | Returns the total space, in bytes, of a drive or network share. |
| GetDriveType | Returns a value indicating the type of a specified drive. |
| GetExtensionName | Returns a string containing the extension name of the file for a specified path. |
| GetFileAttributes | Returns the attributes of files. Read/write or read-only, depending on the attribute. |
| GetFileDateCreated | Returns the date and time that the specified file was created. |
| GetFileDateLastAccessed | Returns the date and time that the specified file was accessed. |
| GetFileDateLastModified | Returns the date and time that the specified file was modified. |
| GetFileName | Returns a string containing the name of the file for a specified path. |
| GetFileShortName | Returns the short name used by programs that require the earlier 8.3 file naming convention. |
| GetFileShortPath | Returns the short path used by programs that require the earlier 8.3 file naming convention. |
| GetFileSize | Returns the size, in bytes, of the specified file. |
| GetFileType | Returns information about the type of a file. |
| GetFileVersion | Returns the version number of a specified file. |
| GetFolderAttributes | Returns the attributes of folders. |
| GetFolderDateCreated | Returns the date and time that the specified folder was created. |
| GetFolderDateLastAccessed | Returns the date and time that the specified folder was last accessed. |
| GetFolderDateLastModified | Returns the date and time that the specified folder was last modified. |
| GetFolderDriveLetter | Returns a string containing the drive letter for a specified folder. |
| GetFolderName | Returns a string containing the name of the folder for a specified path, i.e. the path minus the file name. |
| GetFolderShortName | Returns the short name used by programs that require the earlier 8.3 file naming convention. |
| GetFolderShortPath | Returns the short path used by programs that require the earlier 8.3 file naming convention. |
| GetFolderSize | Returns the size, in bytes, of all files and subfolders contained in the folder. |
| GetFolderType | Returns information about the type of a folder. |
| GetLastResult | Returns the last result code. |
| GetNumDrives | Returns the number of drives. |
| GetNumFiles | Returns the number of files contained in a specified folder, including those with hidden and system file attributes set. |
| GetNumSubFolders | Returns the number of folders contained in a specified folder, including those with hidden and system file attributes set. |
| GetParentFolderName | Returns the folder name for the parent of the specified folder. |
| GetSerialNumber | Returns the decimal serial number used to uniquely identify a disk volume. |
| GetStandardStream | Returns a TextStream object corresponding to the standard input, output, or error stream. |
| GetStdErrStream | Returns a TextStream object corresponding to the standard error stream. |
| GetStdInStream | Returns a TextStream object corresponding to the standard input stream. |
| GetStdOutStream | Returns a TextStream object corresponding to the standard output stream. |
| GetTempName | Returns a randomly generated temporary file or folder name that is useful for performing operations that require a temporary file or folder. |
| GetVolumeName | Returns the volume name of the specified drive. |
| IsDriveReady | Returns True if the specified drive is ready; False if it is not. |
| IsRootFolder | Returns True(-1) if the specified folder is the root folder; False(0) if it is not. |
| MoveFile | Moves one or more files from one location to another. |
| MoveFolder | Moves one or more folders from one location to another. |
| SetFileAttributes | Sets the attributes of files. |
| SetFileName | Sets the name of a specified file. |
| SetFolderAttributes | Sets the attributes of folders. |
| SetFolderName | Sets the name of a specified folder. |
| SetVolumeName | Sets the volume name of the specified drive. |
Appends a name to an existing path.
FUNCTION BuildPath (BYREF cbsPath AS CBSTR, BYREF cbsName AS CBSTR) AS CWSTR
| Name | Description |
|---|---|
| cbsPath | CBSTR. Existing path to which name is appended. Path can be absolute or relative and need not specify an existing folder. |
| cbsName | CBSTR. Name being appended to the existing path. |
CBSTR. The new path.
The BuildPath method inserts an additional path separator between the existing path and the name, only if necessary.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsNewPath AS CBSTR = pFileSys.BuildPath ("C:\MyFolder", "Text.txt")
Copies one or more files from one location to another.
FUNCTION CopyFile (BYREF cbsSource AS CBSTR, BYREF cbsDestination AS CBSTR, _
BYVAL OverWriteFiles AS VARIANT_BOOL = -1) AS HRESULT
| Name | Description |
|---|---|
| cbsSource | CBSTR. Character string file specification, which can include wildcard characters, for one or more files to be copied. |
| cbsDestination | CBSTR. Character string destination where the file or files from source are to be copied. Wildcard characters are not allowed. |
| OverWriteFiles | Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite. |
HRESULT. S_OK (0) on success, or an error code on failure.
Wildcard characters can only be used in the last path component of the cbSource argument.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.CopyFile("C:\MyFolder\MyFile.txt", "C:\MyOtherFolder\MyFile.txt")
Recursively copies a folder from one location to another.
FUNCTION CopyFolder (BYREF cbsSource AS CBSTR, BYREF cbsDestination AS CBSTR, _
BYVAL OverWriteFiles AS VARIANT_BOOL = -1) AS HRESULT
| Name | Description |
|---|---|
| cbsSource | CBSTR. Character string file specification, which can include wildcard characters, for one or more folders to be copied. |
| cbsDestination | CBSTR. Character string destination where the folder and subfolders from source are to be copied (must end with a ""). Wildcard characters are not allowed. |
| OverWriteFiles | Boolean value that indicates if existing folders are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. |
HRESULT. S_OK (0) on success, or an error code on failure.
Wildcard characters can only be used in the last path component of the cbSource argument.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.CopyFolder("C:\MyFolder", "C:\MyOtherFolder\")
Creates a folder.
FUNCTION CreateFolder (BYREF cbsFolderSpec AS CBSTR) AS Afx_IFolder PTR
| Name | Description |
|---|---|
| cbsFolderSpec | CBSTR. String expression that identifies the folder to create. |
IDispatch. Reference to an IFolder object.
An error occurs if the specified folder already exists.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM pFolder AS Afx_Folder PTR
pFolder = pFileSys.CreateFolder("C:\MyNewFolder")
IF pFolder THEN
' ....
pFolder.Release
END IF
Deletes a specified file.
FUNCTION DeleteFile (BYREF cbsFileSpec AS CBSTR, BYVAL bForce AS VARIANT_BOOL = FALSE) AS HRESULT
| Name | Description |
|---|---|
| cbsFileSpec | CBSTR. The name of the file to delete. cbsFileSpec can contain wildcard characters in the last path component. |
| bForce | Boolean value that is true if files with the read-only attribute set are to be deleted; false (default) if they are not. |
HRESULT. S_OK (0) on success, or an error code on failure.
An error occurs if no matching files are found. The DeleteFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.DeleteFile("C:\MyFolder\MyFile.txt")
Deletes a specified folder and its contents.
FUNCTION DeleteFolder (BYREF cbsFolderSpec AS CBSTR, BYVAL bForce AS VARIANT_BOOL = FALSE) AS HRESULT
| Name | Description |
|---|---|
| cbsFolderSpec | CBSTR. The name of the folder to delete. cbsFolderSpec can contain wildcard characters in the last path component. |
| bForce | Boolean value that is true if folders with the read-only attribute set are to be deleted; false (default) if they are not. |
HRESULT. S_OK (0) on success, or an error code on failure.
The DeleteFolder method does not distinguish between folders that have contents and those that do not. The specified folder is deleted regardless of whether or not it has contents.
An error occurs if no matching folders are found. The DeleteFolder method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.DeleteFolder("C:\MyFolder")
Returns True if the specified drive exists; False if it does not.
FUNCTION DriveExists (BYREF cbsDriveSpec AS CBSTR) AS BOOLEAN
| Name | Description |
|---|---|
| cbsDriveSpec | CBSTR. A drive letter or a complete path specification. |
BOOLEAN. True if the specified drive exists; False if it does not.
For drives with removable media, the DriveExists method returns true even if there are no media present. Use the IsDriveReady method to determine if a drive is ready.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM fExists AS BOOLEAN = pFileSys.DriveExists("C:")
Returns a semicolon separated list with the driver letters.
FUNCTION DriveLetters () AS CBSTR
CBSTR. A semicolon separated list with the driver letters.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsLetters AS CBSTR = pFileSys.DriveLetters
Returns True if the specified file exists; False if it does not.
FUNCTION FileExists (BYREF cbsFileSpec AS CBSTR) AS BOOLEAN
| Name | Description |
|---|---|
| cbsFileSpec | CBSTR. The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder. |
Boolean. True if the specified file exists; False if it does not.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM fExists AS BOOLEAN = pFileSys.FileExists("C:\MyFolder\Test.txt")
Returns True if the specified folder exists; False if it does not.
FUNCTION FolderExists (BYREF cbsFolderSpec AS CBSTR) AS BOOLEAN
| Name | Description |
|---|---|
| cbsFolderSpec | CBSTR. The name of the folder whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the folder isn't expected to exist in the current folder. |
Boolean. True if the specified folder exists; False if it does not.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM fExists AS BOOLEAN = pFileSys.FolderExists("C:\MyFolder")
Returns complete and unambiguous path from a provided path specification.
FUNCTION GetAbsolutePathName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. Path specification to change to a complete and unambiguous path. |
Boolean. The path name.
A path is complete and unambiguous if it provides a complete reference from the root of the specified drive. A complete path can only end with a path separator character () if it specifies the root folder of a mapped drive.
Assuming the current directory is c:\mydocuments\reports, the following table illustrates the behavior of the GetAbsolutePathName method.
| pathspec | Returned path |
|---|---|
| "c:" | "c:\mydocuments\reports" |
| "c:.." | "c:\mydocuments" |
| "c:" | "c:" |
| "c:.\may97" | "c:\mydocuments\reports\*.*\may97" |
| "region1" | "c:\mydocuments\reports\region1" |
| "c:....\mydocuments" | "c:\mydocuments" |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetAbsolutePathName("C:\MyFolder\Test.txt")
Returns a string containing the base name of the last component, less any file extension, in a path
FUNCTION GetBaseName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. The path specification for the component whose base name is to be returned. |
Boolean. The base name.
The GetBaseName method returns a zero-length string ("") if no component matches the path argument. The GetBaseName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cwsName AS CWSTR = pFileSys.GetBaseName("C:\MyFolder\Test.txt")
Returns the amount of space available to a user on the specified drive or network share.
FUNCTION GetDriveAvailableSpace (BYREF cbsDrive AS CBSTR) AS DOUBLE
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
DOUBLE. The amount of available space.
The value returned by the GetDriveAvailableSpace method is typically the same as that returned by the GetDriveFreeSpace method. Differences may occur between the two for computer systems that support quotas.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
PRINT pFileSys.GetDriveAvailableSpace("C:")
Returns the type of file system in use for the specified drive or network share.
FUNCTION GetDriveFileSystem (BYREF cbsDrive AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
CBSTR. The type of file system in use.
Available return types include FAT, NTFS, and CDFS.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsFileSystem AS CBSTR = pFileSys.GetDriveFileSystem("C:")
Returns the amount of free space available to a user on the specified drive or network share
FUNCTION GetDriveFreeSpace (BYREF cbsDrive AS CBSTR) AS DOUBLE
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
DOUBLE. The amount of free space.
The value returned by the GetDriveFreeSpace property is typically the same as that returned by the GetDriveAvailableSpace property. Differences may occur between the two for computer systems that support quotas.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
PRINT pFileSys.GetDriveFreeSpace("C:")
Returns a string containing the name of the drive for a specified path.
FUNCTION GetDriveName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. The path. |
CBSTR. The drive name.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetDriveName("C:\MyFolder\Test.txt")
Returns the network share name for a specified drive.
FUNCTION GetDriveShareName (BYREF cbsDrive AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
CBSTR. The share name.
If object is not a network drive, the GetDriveShareName method returns a zero-length string ("").
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsShareName AS CBSTR = pFileSys.GetDriveShareName("H:")
Returns the total space, in bytes, of a drive or network share.
FUNCTION GetDriveTotalSize (BYREF cbsDrive AS CBSTR) AS DOUBLE
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
DOUBLE. The total space in bytes.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
PRINT pFileSys.GetDriveTotalSize("C:")
Returns a value indicating the type of a specified drive.
FUNCTION GetDriveType (BYREF cbsDrive AS CBSTR) AS DRIVETYPECONST
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
The type of the specified drive.
DriveType_UnknownType = 0
DriveType_Removable = 1
DriveType_Fixed = 2
DriveType_Remote = 3
DriveType_CDRom = 4
DriveType_RamDisk = 5
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDriveType AS DRIVETYPECONST = pFileSys.GetDriveType("C:")
DIM t AS CBSTR
SELECT CASE pDrive.DriveType
CASE 0 : t = "Unknown"
CASE 1 : t = "Removable"
CASE 2 : t = "Fixed"
CASE 3 : t = "Network"
CASE 4 : t = "CD-ROM"
CASE 5 : t = "RAM Disk"
END SELECT
Returns a string containing the extension name of the file for a specified path.
FUNCTION GetExtensionName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. The extension name. |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetExtensionName("C:\MyFolder\Test.txt")
Returns the attributes of files.
FUNCTION GetFileAttributes (BYREF cbsFile AS CBSTR) AS FILEATTRIBUTE
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
The file attributes. Can be any of the following values or any logical combination of the following values:
| Constant | Value | Description |
|---|---|---|
| FileAttribute_Normal | 0 | Normal file. No attributes are set. |
| FileAttribute_ReadOnly | 1 | Read-only file. Attribute is read/write. |
| FileAttribute_Hidden | 2 | Hidden file. Attribute is read/write. |
| FileAttribute_System | 4 | System file. Attribute is read/write. |
| FileAttribute_Volume | 8 | Disk drive volume label. Attribute is read-only. |
| FileAttribute_Directory | 16 | Folder or directory. Attribute is read-only. |
| FileAttribute_Archive | 32 | File has changed since last backup. Attribute is read/write. |
| FileAttribute_Alias | 1024 | Link or shortcut. Attribute is read-only. |
| FileAttribute_Compressed | 2048 | Compressed file. Attribute is read-only. |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM lAttr FILEATTRIBUTE = pFileSys.GetFileAttributes("C:\MyPath\MyFile.txt")
Returns the date and time that the specified file was created.
FUNCTION GetFileDateCreated (BYREF cbsFile AS CBSTR) AS DATE_
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
DATE_. The date and time of the file creation. This is a Date Serial number that can be formatted using the Free Basic's Format function. You can also use the wrapper function AfxVariantDateTimeToStr.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDate AS DATE_ = pFileSys.GetFileDateCreated("C:\MyPath\MyFile.txt")
Returns the date and time that the specified file was accesed.
FUNCTION GetFileDateLastAccessed (BYREF cbsFile AS CBSTR) AS DATE_
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
DATE_. The date and time that the file was last accessed. This is a Date Serial number that can be formatted using the Free Basic's Format function. You can also use the wrapper function AfxVariantDateTimeToStr.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDate AS DATE_ = pFileSys.GetFileDateLastAccessed("C:\MyPath\MyFile.txt")
Returns the date and time that the specified file was accessed.
FUNCTION GetFileDateLastModified (BYREF cbsFile AS CBSTR) AS DATE_
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
DATE_. The date and time that the file was last modified. This is a Date Serial number that can be formatted using the Free Basic's Format function. You can also use the wrapper function AfxVariantDateTimeToStr.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDate AS DATE_ = pFileSys.GetFileDateLastModified("C:\MyPath\MyFile.txt")
Returns a string containing the name of the file for a specified path.
FUNCTION GetFileName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. The path to a specific file. |
CBSTR. The file name.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetFileName("C:\MyFolder\Test.txt")
Returns the short name used by programs that require the earlier 8.3 file naming convention.
FUNCTION GetFileShortName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. The path to a specific file. |
CBSTR. The short name for the specified file.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetFileShortName("C:\MyFolder\Test.txt")
Returns the short path used by programs that require the earlier 8.3 file naming convention.
FUNCTION GetFileShortPath (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsPathSpec | CBSTR. The path to a specific file. |
CBSTR. The short path to a specific file.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetFileShortPath("C:\MyFolder\Test.txt")
Returns the size, in bytes, of the specified file.
FUNCTION GetFileSize (BYREF cbsFile AS CBSTR) AS LONG
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
LONG. The size, in bytes, of the file.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nFileSize AS LONG = pFileSys.GetFileSize("C:\MyPath\MyFile.txt")
Returns information about the type of a file. For example, for files ending in .TXT, "Text Document" is returned.
FUNCTION GetFileType (BYREF cbsFile AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
CBSTR. The type of file.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsFileType AS CBSTR = pFileSys.GetFileType("C:\MyPath\MyFile.txt")
Returns the version number of a specified file.
FUNCTION GetFileVersion (BYREF cbsFile AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path (absolute or relative) to a specific file. |
CBSTR. The version number.
The GetFileVersion method returns a zero-length string ("") if cbsFile does not end with the named component.
Note: The GetFileVersion method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsVersion AS CBSTR = pFileSys.GetFileVersion("C:\MyFolder\MyFile.doc")
IF LEN(cbsVersion) THEN
MSGBOX "File version: " & cbsVersion
ELSE
MSGBOX "No version information available"
END IF
DIM pFileSys AS CFileSys
print pFileSys.GetFileVersion("c:\windows\system32\scrrun.dll")
Returns the attributes of folders.
FUNCTION GetFolderAttributes (BYREF cbsFolder AS CBSTR) AS FILEATTRIBUTE
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
The attributes. Can be any of the following values or any logical combination of the following values:
| Constant | Value | Description |
|---|---|---|
| FileAttribute_Normal | 0 | Normal file. No attributes are set. |
| FileAttribute_ReadOnly | 1 | Read-only file. Attribute is read/write. |
| FileAttribute_Hidden | 2 | Hidden file. Attribute is read/write. |
| FileAttribute_System | 4 | System file. Attribute is read/write. |
| FileAttribute_Volume | 8 | Disk drive volume label. Attribute is read-only. |
| FileAttribute_Directory | 16 | Folder or directory. Attribute is read-only. |
| FileAttribute_Archive | 32 | File has changed since last backup. Attribute is read/write. |
| FileAttribute_Alias | 1024 | Link or shortcut. Attribute is read-only. |
| FileAttribute_Compressed | 2048 | Compressed file. Attribute is read-only. |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM lAttr FILEATTRIBUTE = pFileSys.GetFolderAttributes("C:\MyPath")
Returns the date and time that the specified folder was created.
FUNCTION GetFolderDateCreated (BYREF cbsFolder AS CBSTR) AS DATE_
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
DATE_. The date and time that the folder was created. This is a Date Serial number that can be formatted using the Free Basic's Format function. You can also use the wrapper function AfxVariantDateTimeToStr.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDate AS DATE_ = pFileSys.GetFolderDateCreated("C:\MyPath")
Returns the date and time that the specified folder was last accessed.
FUNCTION GetFolderDateLastAccessed (BYREF cbsFolder AS CBSTR) AS DATE_
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
DATE_. The date and time that the folder was last accessed. This is a Date Serial number that can be formatted using the Free Basic's Format function. You can also use the wrapper function AfxVariantDateTimeToStr.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDate AS DATE_ = pFileSys.GetFolderDateLastAccessed("C:\MyPath)
Returns the date and time that the specified folder was last modified.
FUNCTION GetFolderDateLastModified (BYREF cbsFolder AS CBSTR) AS DATE_
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
DATE_. The date and time that the folder was last modified. This is a Date Serial number that can be formatted using the Free Basic's Format function. You can also use the wrapper function AfxVariantDateTimeToStr.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nDate AS DATE_ = pFileSys.GetFolderDateLastModified("C:\MyPath)
Returns a string containing the drive letter for a specified folder.
FUNCTION GetFolderDriveLetter (BYREF cbsFolder AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
CBSTR. The drive letter of the folder.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsDriveLetter AS CBSTR = pFileSys.GetFolderDriveLetter("c:\MyFolder)
Returns a string containing the name of the folder for a specified path, i.e. the path minus the file name.
FUNCTION GetFolderName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
CBSTR. The name of the folder.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetFolderName("C:\MyFolder\Test.txt")
Returns the short name used by programs that require the earlier 8.3 file naming convention.
FUNCTION GetFolderShortName (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
CBSTR. The short name for the specified folder.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsFolderShortPath AS CBSTR = pFileSys.GetFolderShortName("c:\MyFolder)
Returns the short path used by programs that require the earlier 8.3 file naming convention.
FUNCTION GetFolderShortPath (BYREF cbsPathSpec AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
CBSTR. The short path for the specified folder.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsFolderShortPath AS CBSTR = pFileSys.GetFolderShortPath("c:\MyFolder)
Returns the size, in bytes, of all files and subfolders contained in the folder.
FUNCTION GetFolderSize (BYREF cbsFolder AS CBSTR) AS LONG
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
LONG. The size, in bytes, of all files and subfolders contained in the folder.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nFolderSize AS LONG = pFileSys.GetFolderSize("C:\MyPath")
Returns information about the type of a folder.
FUNCTION GetFolderType (BYREF cbsFolder AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
CBSTR. The type of folder.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsFolderType AS CBSTR = pFileSys.GetFolderType("c:\MyFolder)
Returns the last result code.
FUNCTION GetLastResult () AS HRESULT
HRESULT. The result code returned by the last executed method.
Returns the number of drives.
FUNCTION GetNumDrives () AS LONG
LONG. The number of drives.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM numDrives AS LONG = pFileSys.GetNumDrives
Returns the number of files contained in a specified folder, including those with hidden and system file attributes set.
FUNCTION GetNumFiles (BYREF cbsFolder AS CBSTR) AS LONG
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
LONG. The number of files.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM numFiles AS LONG = pFileSys.GetNumFiles("C:\MyFolder")
Returns the number of files contained in a specified folder, including those with hidden and system file attributes set.
FUNCTION GetNumSubFolders (BYREF cbsFolder AS CBSTR) AS LONG
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
LONG. The number of subfolders.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM numSubFolders AS LONG = pFileSys.GetNumSubFolders("C:\MyFolder")
Returns the folder name for the parent of the specified folder.
FUNCTION GetParentFolderName (BYREF cbsFolder AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
CBSTR. The name of the parent folder, or a empty string if the folder has no parent.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsParentFolderName AS CBSTR = pFileSys.GetParentFolderName("C:\MyFolder\MySubfolder")
Returns the decimal serial number used to uniquely identify a disk volume.
FUNCTION GetSerialNumber (BYREF cbsDrive AS CBSTR) AS LONG
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
LONG. The serial number.
You can use the GetSerialNumber method to ensure that the correct disk is inserted in a drive with removable media.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM nSerialNumber AS LONG = pFileSys.GetSerialNumber("C:")
Returns a TextStream object corresponding to the standard input, output, or error stream.
FUNCTION GetStandardStream (BYVAL nStreamType AS STANDARDSTREAMTYPES, _
BYVAL bUnicode AS VARIANT_BOOL = FALSE) AS Afx_ITextStream PTR
| Name | Description |
|---|---|
| nStreamType | LONG. Can be one of three constants: StandardStreamTypes_StdErr, StandardStreamTypes_StdIn, or StandardStreamTypes_StdOut. |
| bUnicode | Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it is created as an ASCII file. If omitted, an ASCII file is assumed. |
A pointer to the ITextStream interface of the requested standard stream.
The nStreamType argument can have any of the following settings:
| Constant | Constant | Description |
|---|---|---|
| StandardStreamTypes_StdIn | 0 | Returns a TextStream object corresponding to the standard input stream. |
| StandardStreamTypes_StdOut | 1 | Returns a TextStream object corresponding to the standard output stream. |
| StandardStreamTypes_StdErr | 2 | Returns a TextStream object corresponding to the standard error stream. |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM pStm AS Afx_ITextStream PTR = pFileSys.GetStandardStream(StandardStreamTypes_StdOut)
Returns a TextStream object corresponding to the standard error stream.
FUNCTION GetStdErrStream (BYVAL bUnicode AS VARIANT_BOOL = FALSE) AS Afx_ITextStream PTR
| Name | Description |
|---|---|
| bUnicode | Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it is created as an ASCII file. If omitted, an ASCII file is assumed. |
A pointer to the ITextStream interface of the standard error stream.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM pStm AS Afx_ITextStream PTR = pFileSys.GetStdErrStream
Returns a TextStream object corresponding to the standard input stream.
FUNCTION GetStdInStream (BYVAL bUnicode AS VARIANT_BOOL = FALSE) AS Afx_ITextStream PTR
| Name | Description |
|---|---|
| bUnicode | Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it is created as an ASCII file. If omitted, an ASCII file is assumed. |
A pointer to the ITextStream interface of the standard input stream.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM pStm AS Afx_ITextStream PTR = pFileSys.GetStdInStream
Returns a TextStream object corresponding to the standard output stream.
FUNCTION GetStdOutStream (BYVAL bUnicode AS VARIANT_BOOL = FALSE) AS Afx_ITextStream PTR
| Name | Description |
|---|---|
| bUnicode | Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it is created as an ASCII file. If omitted, an ASCII file is assumed. |
A pointer to the ITextStream interface of the standard output stream.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM pStm AS Afx_ITextStream PTR = pFileSys.GetStdOutStream
Returns a randomly generated temporary file or folder name that is useful for performing operations that require a temporary file or folder.
FUNCTION GetTempName () AS CBSTR
CBSTR. The temporary name.
The GetTempName method does not create a file. It provides only a temporary file name that can be used with CreateTextFile to create a file.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsName AS CBSTR = pFileSys.GetTempName
Returns the volume name of the specified drive.
FUNCTION GetVolumeName (BYREF cbsDrive AS CBSTR) AS CBSTR
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
CBSTR. The volume name.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM cbsVolumeName AS CBSTR = pFileSys.GetVolumeName("C:")
Returns True if the specified drive is ready; False if it is not.
FUNCTION IsDriveReady (BYREF cbsDrive AS CBSTR) AS BOOLEAN
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
BOOLEAN. True if the specified drive is ready; False if it is not.
For removable-media drives and CD-ROM drives, IsDriveReady returns True only when the appropriate media is inserted and ready for access.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM bIsReady AS BOOLEAN = pFileSys.IsDriveReady("C:")
Returns True(-1) if the specified folder is the root folder; False(0) if it is not.
FUNCTION IsRootFolder (BYREF cbsFolder AS CBSTR) AS BOOLEAN
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
BOOLEAN. True(-1) if the specified folder is the root folder; False(0) if it is not.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
DIM bIsRoot AS BOOLEAN = pFileSys.IsRootFolder("C:\MyFolder")
Moves one or more files from one location to another.
FUNCTION MoveFile (BYREF cbsSource AS CBSTR, BYREF cbsDestination AS CBSTR) AS HRESULT
| Name | Description |
|---|---|
| cbsSource | CBSTR. The path to the file or files to be moved. The cbsSource argument string can contain wildcard characters in the last path component only. |
| cbsDestination | CBSTR. Destination where the file is to be moved. Wildcard characters are not allowed. |
HRESULT. S_OK (0) on success, or an error code on failure.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.MoveFile("C:\MyFolder\MyFile.txt", "C:\MyOtherFolder\")
Moves one or more folders from one location to another.
FUNCTION MoveFolder (BYREF cbsSource AS CBSTR, BYREF cbsDestination AS CBSTR) AS HRESULT
| Name | Description |
|---|---|
| cbsSource | CBSTR. The path to the folder or folders to be moved. The cbsSource argument string can contain wildcard characters in the last path component only. |
| cbsDestination | CBSTR. Destination where the folder is to be moved (must end with a "\"). Wildcard characters are not allowed. |
HRESULT. S_OK (0) on success, or an error code on failure.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.MoveFolder("C:\MyFolder", "C:\MyNewFolder\")
Sets the attributes of files.
FUNCTION SetFileAttributes (BYREF cbsFile AS CBSTR, BYVAL lAttr AS FILEATTRIBUTE) AS HRESULT
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
| lAttr | LONG. The new value for the attributes of the specified file. |
The file attributes. Can be any of the following values or any logical combination of the following values:
| Constant | Value | Description |
|---|---|---|
| FileAttribute_Normal | 0 | Normal file. No attributes are set. |
| FileAttribute_ReadOnly | 1 | Read-only file. Attribute is read/write. |
| FileAttribute_Hidden | 2 | Hidden file. Attribute is read/write. |
| FileAttribute_System | 4 | System file. Attribute is read/write. |
| FileAttribute_Volume | 8 | Disk drive volume label. Attribute is read-only. |
| FileAttribute_Directory | 16 | Folder or directory. Attribute is read-only. |
| FileAttribute_Archive | 32 | File has changed since last backup. Attribute is read/write. |
| FileAttribute_Alias | 1024 | Link or shortcut. Attribute is read-only. |
| FileAttribute_Compressed | 2048 | Compressed file. Attribute is read-only. |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.SetFileAttributes("C:\MyPath\MyFile.txt", 33) ' FileAttribute_Archive OR FileAttribute_Normal
Sets the name of a specified file.
FUNCTION SetFileName (BYREF cbsFile AS CBSTR, BYREF cbsName AS CBSTR) AS HRESULT
| Name | Description |
|---|---|
| cbsFile | CBSTR. The path to a specific file. |
| cbsName | CBSTR. The new name of the file. |
HRESULT. S_OK (0) on success, or an error code on failure.
You only have to pass the new name of the file, not the full path.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.SetFileName("c:\MyFolder\Test.txt", "NewName")
Sets the attributes of folders.
FUNCTION SetFolderAttributes (BYREF cbsFolder AS CBSTR, BYVAL lAttr AS FILEATTRIBUTE) AS HRESULT
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
| lAttr | LONG. The new value for the attributes of the specified folder. |
The lAttr argument can have any of the following values or any logical combination of the following values:
| Constant | Value | Description |
|---|---|---|
| FileAttribute_Normal | 0 | Normal file. No attributes are set. |
| FileAttribute_ReadOnly | 1 | Read-only file. Attribute is read/write. |
| FileAttribute_Hidden | 2 | Hidden file. Attribute is read/write. |
| FileAttribute_System | 4 | System file. Attribute is read/write. |
| FileAttribute_Volume | 8 | Disk drive volume label. Attribute is read-only. |
| FileAttribute_Directory | 16 | Folder or directory. Attribute is read-only. |
| FileAttribute_Archive | 32 | File has changed since last backup. Attribute is read/write. |
| FileAttribute_Alias | 1024 | Link or shortcut. Attribute is read-only. |
| FileAttribute_Compressed | 2048 | Compressed file. Attribute is read-only. |
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.SetFolderAttributes("C:\MyPath\MyFile.txt", 17) ' FileAttribute_Directory OR FileAttribute_ReadOnly
Sets the name of a specified folder.
FUNCTION SetFolderName (BYREF cbsFolder AS CBSTR, BYREF cbsName AS CBSTR) AS HRESULT
| Name | Description |
|---|---|
| cbsFolder | CBSTR. The path to a specific folder. |
| cbsName | CBSTR. The new name of the folder. |
HRESULT. S_OK (0) on success, or an error code on failure.
You only have to pass the new name of the folder, not the full path.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.SetFolderName("c:\MyFolder", "NewName")
Sets the name of a specified drive.
FUNCTION SetVolumeName (BYREF cbsDrive AS CBSTR, BYREF cbsName AS CBSTR) AS HRESULT
| Name | Description |
|---|---|
| cbsDrive | CBSTR. The drive letter. For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. |
| cbsName | CBSTR. The volume name. |
HRESULT. S_OK (0) on success, or an error code on failure.
#INCLUDE ONCE "Afx/CFileSys.inc"
DIM pFileSys AS CFileSys
pFileSys.SetVolumeName("C:", "VolumeName")